package com.zhuna.www.view;


import com.zhuna.www.po.User;
import com.zhuna.www.service.UserService;
import com.zhuna.www.service.impl.UserServiceImp1;

import java.util.Scanner;

public class AppMain {
    private static final Scanner scanner = new Scanner(System.in);
    private static final UserService userService = new UserServiceImp1();
    private static User currentUser = null; // 当前已登录的用户

    public static void main(String[] args) {
        while (true) {
            System.out.println("\n=== 欢迎使用用户管理系统 ===");
            System.out.println("1. 登录");
            System.out.println("2. 注册");
            System.out.println("3. 退出");
            System.out.print("请输入选项：");

            String input = scanner.nextLine();

            switch (input) {
                case "1":
                    try{
                        System.out.println("请输入用户名：");
                        String name = scanner.nextLine();
                        System.out.println("请输入密码：");
                        String password = scanner.nextLine();
                        currentUser =userService.login(name,password);
                        if (currentUser == null) {
                            System.out.println("登录失败：用户名或密码错误！");
                            return;
                        }
                        System.out.println("登录成功，欢迎 " + currentUser.getName() + "！");
                        // 根据身份跳转
                        switch (currentUser.getRole()) {
                            case CLIENT:
                                new ClientMenu().menuforclient(currentUser);
                                break;
                            case MERCHANT:
                                new MerchantMenu().menuformerchant(currentUser);
                                break;
                            case ADMIN:
                                new AdminMenu().menuForadmin(currentUser);
                                break;
                            default:
                                System.out.println("未知身份，无法进入系统");
                        }




                    }catch (Exception e){
                        System.out.println("登录出错：" + e.getMessage());
                        e.printStackTrace();
                    }
                case "2":
//                    try{//注册之后根据身份跳转页面
//                        System.out.println("请输入用户名");
//                        userService.register();}catch (){}

                    break;
                case "3":
                    System.out.println("谢谢使用，再见！");
                    return;
                default:
                    System.out.println("无效输入，请重新选择。");
            }
        }


    }

//    private static void login(){
//        System.out.print("请输入用户名：");
//        String username = scanner.nextLine();
//        System.out.print("请输入密码：");
//        String password = scanner.nextLine();
//
//        try {
//            User user = userService.login(username, password);
//            if (user != null) {
//                System.out.println("登录成功，欢迎您，" + user.getName() + "！");
//                switch (user.getRole()) {
//                    case USER:
//                        new CustomerMenu().show(user);
//                        break;
//                    case MERCHANT:
//                        new MerchantMenu().show(user);
//                        break;
//                    case ADMIN:
//                        new AdminMenu().show(user);
//                        break;
//                    default:
//                        System.out.println("未知身份，无法分配界面！");
//                }
//            }
//    }
//        catch (){}
}
